package com.parktech.sun.domain.model.industryservice;

import com.parktech.sun.domain.model.BaseEntity;
import com.parktech.sun.domain.model.ContentEntity;
import com.parktech.sun.utils.HTMLHelper;
import org.xml.sax.SAXException;

import javax.persistence.*;
import java.io.IOException;
import java.util.Date;

/**
 * User: Think
 * Date: 11-1-12
 * Time: 下午10:16
 */
@Entity
public class IndustryService extends BaseEntity {

    private String imageName;

    private String title;

    private String summary;

    private String content;

    private String publishDate = df.format(new Date());

    private Integer publishStatus;

    private Integer orderCode = -1;

    public IndustryService() {
    }

    public IndustryService(Long id) {
        this.id = id;
    }

    public String getImageName() {
        return imageName;
    }

    public void setImageName(String imageName) {
        this.imageName = imageName;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column(length = 200)
    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(length = 2147483647)
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getPublishDate() {
        return publishDate;
    }

    public void setPublishDate(String publishDate) {
        this.publishDate = publishDate;
    }

    public Integer getPublishStatus() {
        return publishStatus;
    }

    public void setPublishStatus(Integer publishStatus) {
        this.publishStatus = publishStatus;
    }

    public Integer getOrderCode() {
        return orderCode;
    }

    public void setOrderCode(Integer orderCode) {
        this.orderCode = orderCode;
    }

    @Transient
    public String getContentText() {
        try {
            return HTMLHelper.getContentText(content);
        } catch (IOException e) {
            e.printStackTrace();
            return content;
        } catch (SAXException e) {
            e.printStackTrace();
            return content;
        }
    }
}
